package battlecruiser.ship.placement.shipyard;

import battlecruiser.board.ObservableBoard;
import battlecruiser.ship.placement.ship.Ship;
import battlecruiser.ship.placement.ship.ShipType;
import org.apache.log4j.Logger;

import java.util.Map;

/**
 * @author Yakiv Tymoshenko
 * @since 02.10.12
 */
public class AutomaticShipyard extends Shipyard {

    private static Logger LOG = Logger.getLogger(AutomaticShipyard.class);

    public AutomaticShipyard(ObservableBoard observableBoard) {
        super(observableBoard);
    }


    @Override
    public void deployFleet() {
        Ship ship;
        Map<ShipType, Integer> rules = getFleet().getShipPlacingRules();
        for (Map.Entry<ShipType, Integer> rule : rules.entrySet()) {
            for (int i = 0; i < rule.getValue(); i++) {
                ship = Ship.random(this.observableBoard, rule.getKey());
                deployShip(ship);
            }
        }
        getFleet().markReady();
        observableBoard.setFleet(fleet);


        LOG.debug("\n\nThe fleet has been deployed: \n");
        for (Ship s : getFleet().getShips()) {
            LOG.debug(s);
        }
        LOG.debug("\n" + getObservableBoard());
    }
}
